import org.junit.Test;

import java.sql.SQLOutput;
import java.util.Arrays;
import java.util.List;

public class StreamDemo02 {

    @Test
    public void test1(){
        List<Employee> list = EmployeeData.getEmployees();
        //薪资大于7000
        list.stream().filter(e->e.getSalary()>7000).forEach(System.out::println);
        System.out.println("-----------------------------------------------------");
        //3条
        list.stream().limit(3).forEach(System.out::println);
        System.out.println("-----------------------------------------------------");
        //跳过前多少条数据，超过总数返回空
        list.stream().skip(30).forEach(System.out::println);
        //去重
        list.add(new Employee(1003,"刘强东",33,3000.82));
        list.add(new Employee(1003,"刘强东",33,3000.82));
        list.add(new Employee(1003,"刘强东",33,3000.82));
        list.add(new Employee(1003,"刘强东",33,3000.82));
        list.add(new Employee(1003,"刘强东",33,3000.82));
        list.stream().distinct().forEach(System.out::println);
    }

    @Test
    public void test2(){
        List<String> list = Arrays.asList("aa", "bb", "cc", "dd");
        list.stream().map(str->str.toUpperCase()).forEach(System.out::println);
        list.stream().map(String::toUpperCase).forEach(System.out::println);

        //获取员工姓名长度大于3的员工的姓名
        List<Employee> employees = EmployeeData.getEmployees();
        employees.stream().map(employee -> employee.getName()).filter(name->name.length()>3).forEach(System.out::println);
    }
}
